package com.b2bpsssm.controller.sysmanage;/**
 * @author JunYu
 * @create 2022-08-13--15:49
 */

import com.b2bpsssm.common.R;
import com.b2bpsssm.simulate.GenerateSysActionLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @program: B2BPSSMSystem
 * @description: 系统日志控制器
 * @author: JunYu
 * @create: 2022-08-13 15:49
 **/
@Controller
@EnableSwagger2
@RequestMapping(value = "/sys_log")
@Api(value = "系统日志模块", tags = "系统日志模块api")
public class SysLogController {
    //删除操作日志
    @RequestMapping(value = "/delSystemLogById", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "删除操作日志", notes = "根据操作日志id来删除密码删除操作日志", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "操作日志id", paramType = "int", dataType = "String", required = true),
            }
    )
    public R addRole(@RequestParam("id") int id) {
        R r = new R();
        r.setCode(200);
        r.setMassage("删除操作日志成功，删除的记录编号为" + id);
        return r;
    }

    //导出所有操作日志
    @RequestMapping(value = "/exportSystemLog", method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "导出所有操作日志", notes = "导出所有操作日志，无需任何参数", httpMethod = "get", response =R.class)
    public R exportSystemLog() {
        R r = new R();
        r.setCode(200);
        r.setMassage("导出操作日志成功");
        return r;
    }

    //查询所有日志
    @RequestMapping(value = "/findSystemLogList", method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "查询所有日志", notes = "查询所有日志，要求传入当前页面和页面长度", httpMethod = "get", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "currentPage", value = "当前页码", paramType = "int", dataType = "String", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "页码长度", paramType = "int", dataType = "String", required = true)
            }
    )
    public R findSystemLogList(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        System.out.println("当前页面为" + currentPage);
        R r = new R();
        r.setCode(200);
        r.setMassage("查询所有日志成功");
        r.setData(GenerateSysActionLog.generateList(pageSize));
        return r;
    }

    //通过员工姓名查看日志
    @RequestMapping(value = "/findSystemLogByOprName",method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "通过员工姓名查看日志", notes = "输入员工姓名后，通过员工姓名查看日志", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "user_name", value = "员工姓名", paramType = "String", dataType = "json", required = true)
            }
    )
    public R findSystemLogByOprName(@RequestParam("user_name") String user_name) {
        R r = new R();
        r.setCode(200);
        r.setMassage("通过员工姓名查看日志，查询的员工姓名为" + user_name);
        r.setData(GenerateSysActionLog.generateLog());
        return r;
    }
}
